
<!DOCTYPE HTML>
<html lang="" >
    <head>
        <meta charset="UTF-8">
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <title>BroadcastReceiver · GitBook</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="description" content="">
        <meta name="generator" content="GitBook 3.2.3">
        
        
        
    
    <link rel="stylesheet" href="../../gitbook/style.css">

    
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-highlight/website.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-search/search.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-fontsettings/website.css">
                
            
        

    

    
        
    
        
    
        
    
        
    
        
    
        
    

        
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../../gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="../../gitbook/images/favicon.ico" type="image/x-icon">

    
    <link rel="next" href="../Fragment.html" />
    
    
    <link rel="prev" href="ContentProvider.html" />
    

    </head>
    <body>
        
<div class="book">
    <div class="book-summary">
        
            
<div id="book-search-input" role="search">
    <input type="text" placeholder="Type to search" />
</div>

            
                <nav role="navigation">
                


<ul class="summary">
    
    

    

    
        
        
    
        <li class="chapter " data-level="1.1" data-path="../../">
            
                <a href="../../">
            
                    
                    介绍
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2" data-path="../">
            
                <a href="../">
            
                    
                    Android
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.2.1" data-path="../Activity.md">
            
                <span>
            
                    
                    四大组件
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.2.1.1" data-path="Activity.html">
            
                <a href="Activity.html">
            
                    
                    Activity
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.1.2" data-path="Service.html">
            
                <a href="Service.html">
            
                    
                    Service
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.1.3" data-path="ContentProvider.html">
            
                <a href="ContentProvider.html">
            
                    
                    ContentProvider
            
                </a>
            

            
        </li>
    
        <li class="chapter active" data-level="1.2.1.4" data-path="BroadcastReceiver.html">
            
                <a href="BroadcastReceiver.html">
            
                    
                    BroadcastReceiver
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.2.2" data-path="../Fragment.html">
            
                <a href="../Fragment.html">
            
                    
                    Fragment
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.3" data-path="../Context.html">
            
                <a href="../Context.html">
            
                    
                    Context
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.4" data-path="../View.html">
            
                <a href="../View.html">
            
                    
                    View
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.5" data-path="../动画.html">
            
                <a href="../动画.html">
            
                    
                    动画
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.6" data-path="../WebView.html">
            
                <a href="../WebView.html">
            
                    
                    WebView
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.7" data-path="../ListView与RecyclerView.html">
            
                <a href="../ListView与RecyclerView.html">
            
                    
                    ListView与RecyclerView
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.8" data-path="../线程.html">
            
                <a href="../线程.html">
            
                    
                    线程
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.9" data-path="../进程.html">
            
                <a href="../进程.html">
            
                    
                    进程
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.10" data-path="../序列化.html">
            
                <a href="../序列化.html">
            
                    
                    序列化
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.11" data-path="../图片加载与Bitmap.html">
            
                <a href="../图片加载与Bitmap.html">
            
                    
                    图片加载与Bitmap
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.12" data-path="../内存泄漏与内存溢出.html">
            
                <a href="../内存泄漏与内存溢出.html">
            
                    
                    内存泄漏与内存溢出
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.13" data-path="../ANR.html">
            
                <a href="../ANR.html">
            
                    
                    ANR
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.14" data-path="../SparseArray.html">
            
                <a href="../SparseArray.html">
            
                    
                    SparseArray
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.15" data-path="../网络.html">
            
                <a href="../网络.html">
            
                    
                    网络
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.16" data-path="../性能优化.html">
            
                <a href="../性能优化.html">
            
                    
                    性能优化
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.17" data-path="../适配.html">
            
                <a href="../适配.html">
            
                    
                    适配
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.18" data-path="../架构设计.html">
            
                <a href="../架构设计.html">
            
                    
                    架构设计
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.19" data-path="../Java虚拟机与Dalvik、ART虚拟机的区别.html">
            
                <a href="../Java虚拟机与Dalvik、ART虚拟机的区别.html">
            
                    
                    Java虚拟机与Dalvik、ART虚拟机的区别
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.20" data-path="../ActivityThread、AMS、WMS的工作原理.html">
            
                <a href="../ActivityThread、AMS、WMS的工作原理.html">
            
                    
                    ActivityThread、AMS、WMS的工作原理
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.21" data-path="../混合开发.html">
            
                <a href="../混合开发.html">
            
                    
                    混合开发
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.22" data-path="../插件化.html">
            
                <a href="../插件化.html">
            
                    
                    插件化
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.23" data-path="../第三方库.html">
            
                <a href="../第三方库.html">
            
                    
                    第三方库
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    

    
        
        <li class="divider"></li>
        
        
    
        <li class="chapter " data-level="2.1" data-path="../../Java/REAM.html">
            
                <a href="../../Java/REAM.html">
            
                    
                    Java
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="2.1.1" data-path="../../Java/Java基础.html">
            
                <a href="../../Java/Java基础.html">
            
                    
                    Java基础
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.2" data-path="../../Java/JVM.html">
            
                <a href="../../Java/JVM.html">
            
                    
                    JVM
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.3" data-path="../../Java/数据结构.html">
            
                <a href="../../Java/数据结构.html">
            
                    
                    数据结构
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.4" data-path="../../Java/多线程.html">
            
                <a href="../../Java/多线程.html">
            
                    
                    多线程
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.5" data-path="../../Java/应用类型的区别与使用场景.html">
            
                <a href="../../Java/应用类型的区别与使用场景.html">
            
                    
                    引用类型的区别与使用场景
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.6" data-path="../../Java/异常处理.html">
            
                <a href="../../Java/异常处理.html">
            
                    
                    异常处理
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.7" data-path="../../Java/设计模式.html">
            
                <a href="../../Java/设计模式.html">
            
                    
                    设计模式
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.8" data-path="../../Java/算法.html">
            
                <a href="../../Java/算法.html">
            
                    
                    算法
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    

    
        
        <li class="divider"></li>
        
        
    
        <li class="chapter " data-level="3.1" data-path="../../Http/">
            
                <a href="../../Http/">
            
                    
                    网络
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="3.1.1" data-path="../../Http/网络分层.html">
            
                <a href="../../Http/网络分层.html">
            
                    
                    网络分层
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.1.2" data-path="../../Http/http.html">
            
                <a href="../../Http/http.html">
            
                    
                    Http
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.1.3" data-path="../../Http/Https.html">
            
                <a href="../../Http/Https.html">
            
                    
                    Https
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.1.4" data-path="../../Http/TCP.html">
            
                <a href="../../Http/TCP.html">
            
                    
                    TCP
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.1.5" data-path="../../Http/Socket.html">
            
                <a href="../../Http/Socket.html">
            
                    
                    Socket
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    

    

    <li class="divider"></li>

    <li>
        <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
            Published with GitBook
        </a>
    </li>
</ul>


                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                
                    

<div class="book-header" role="navigation">
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href="../.." >BroadcastReceiver</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
<div id="book-search-results">
    <div class="search-noresults">
    
                                <section class="normal markdown-section">
                                
                                <h1 id="broadcastreceiver">BroadcastReceiver</h1>
<h3 id="&#x8BF7;&#x63CF;&#x8FF0;&#x5BF9;-broadcastreceiver-&#x7684;&#x7406;&#x89E3;">&#x8BF7;&#x63CF;&#x8FF0;&#x5BF9; BroadcastReceiver &#x7684;&#x7406;&#x89E3;</h3>
<p>BoradcatReceiver &#x662F;&#x5E7F;&#x64AD;&#x63A5;&#x6536;&#x8005;&#xFF0C;&#x662F; Android &#x56DB;&#x5927;&#x7EC4;&#x4EF6;&#x4E2D;&#x552F;&#x4E00;&#x53EF;&#x4EE5;&#x52A8;&#x6001;&#x6CE8;&#x518C;&#x7684;&#x7EC4;&#x4EF6;&#xFF0C;&#x4E13;&#x6CE8;&#x4E8E;&#x63A5;&#x6536;&#x5E7F;&#x64AD;&#x4FE1;&#x606F;&#x5E76;&#x5904;&#x7406;&#x3002;</p>
<h3 id="&#x5E7F;&#x64AD;&#x7684;&#x5206;&#x7C7B;">&#x5E7F;&#x64AD;&#x7684;&#x5206;&#x7C7B;</h3>
<ul>
<li><p>&#x666E;&#x901A;&#x5E7F;&#x64AD;</p>
<p>&#x901A;&#x8FC7; context.sendBroadcast &#x53D1;&#x9001;&#xFF0C;&#x53EF;&#x4EE5;&#x5E76;&#x884C;&#x53D1;&#x9001;</p>
</li>
</ul>
<pre><code class="lang-java">Intent intent = <span class="hljs-keyword">new</span> Intent();
<span class="hljs-comment">//&#x5BF9;&#x5E94;BroadcastReceiver&#x4E2D;intentFilter&#x7684;action</span>
intent.setAction(<span class="hljs-string">&quot;BROADCAST_ACTION&quot;</span>);
<span class="hljs-comment">//&#x53D1;&#x9001;&#x5E7F;&#x64AD;</span>
sendBroadcast(intent);
</code></pre>
<p>&#x200B;    &#x82E5;&#x88AB;&#x6CE8;&#x518C;&#x7684;&#x5E7F;&#x64AD;&#x63A5;&#x6536;&#x8005;&#x6CE8;&#x518C;&#x65F6;&#x7684; intentFilter &#x4E2D;&#x7684; action &#x4E0E;&#x4E4B;&#x5339;&#x914D;&#xFF0C;&#x90A3;&#x4E48;&#x5728;&#x5C31;&#x4F1A;&#x63A5;&#x6536;&#x5230;&#x8FD9;&#x4E2A;&#x5E7F;&#x64AD;&#xFF0C;&#x56DE;&#x8C03; onReceive&#x3002;</p>
<pre><code class="lang-java">&lt;receiver 
    //&#x6B64;&#x5E7F;&#x64AD;&#x63A5;&#x6536;&#x8005;&#x7C7B;&#x662F;mBroadcastReceiver
    android:name=&quot;.mBroadcastReceiver&quot; &gt;
    //&#x7528;&#x4E8E;&#x63A5;&#x6536;&#x7F51;&#x7EDC;&#x72B6;&#x6001;&#x6539;&#x53D8;&#x65F6;&#x53D1;&#x51FA;&#x7684;&#x5E7F;&#x64AD;
    &lt;intent-filter&gt;
        &lt;action android:name=&quot;BROADCAST_ACTION&quot; /&gt;
    &lt;/intent-filter&gt;
&lt;/receiver&gt;
</code></pre>
<pre><code class="lang-java">IntentFilter intentFilter = <span class="hljs-keyword">new</span> IntentFilter();
intentFilter.addAction(<span class="hljs-string">&quot;BROADCAST_ACTION&quot;</span>);
registerReceiver(<span class="hljs-keyword">new</span> MyBroadcastReceiver(),intentFilter);
</code></pre>
<ul>
<li><p>&#x6709;&#x5E8F;&#x5E7F;&#x64AD;</p>
<p>&#x901A;&#x8FC7; content.sendOrderBroadcast &#x53D1;&#x9001;&#xFF0C;&#x53D1;&#x51FA;&#x7684;&#x5E7F;&#x64AD;&#x88AB;&#x5E7F;&#x64AD;&#x63A5;&#x6536;&#x8005;&#x6309;&#x5148;&#x540E;&#x987A;&#x5E8F;&#x63A5;&#x6536;</p>
<p>&#x5E7F;&#x64AD;&#x63A5;&#x6536;&#x8005;&#x63A5;&#x6536;&#x5E7F;&#x64AD;&#x7684;&#x987A;&#x5E8F;&#x89C4;&#x5219;&#xFF1A;</p>
<ul>
<li>&#x6309;&#x7167;&#x4F18;&#x5148;&#x7EA7;(Priority)&#x4ECE;&#x5927;&#x5230;&#x5C0F;&#x6392;&#x5E8F;</li>
<li>&#x4F18;&#x5148;&#x7EA7;&#x76F8;&#x540C;&#x52A8;&#x6001;&#x6CE8;&#x518C;&#x4F18;&#x5148;</li>
</ul>
<p>&#x7279;&#x70B9;</p>
<ul>
<li>&#x5E7F;&#x64AD;&#x6309;&#x987A;&#x5E8F;&#x63A5;&#x6536;</li>
<li>&#x5148;&#x63A5;&#x6536;&#x7684;&#x5E7F;&#x64AD;&#x63A5;&#x6536;&#x8005;&#x53EF;&#x4EE5;&#x5BF9;&#x5E7F;&#x64AD;&#x8FDB;&#x884C;&#x622A;&#x65AD;&#xFF0C;&#x4E4B;&#x540E;&#x7684;&#x5E7F;&#x64AD;&#x63A5;&#x6536;&#x8005;&#x4E0D;&#x4F1A;&#x518D;&#x63A5;&#x6536;&#x5230;&#x8FD9;&#x4E2A;&#x5E7F;&#x64AD;</li>
<li>&#x5148;&#x63A5;&#x6536;&#x7684;&#x5E7F;&#x64AD;&#x63A5;&#x6536;&#x8005;&#x53EF;&#x4EE5;&#x5BF9;&#x5E7F;&#x64AD;&#x8FDB;&#x884C;&#x4FEE;&#x6539;&#xFF0C;&#x4E4B;&#x540E;&#x7684;&#x5E7F;&#x64AD;&#x63A5;&#x6536;&#x8005;&#x6536;&#x5230;&#x7684;&#x662F;&#x4FEE;&#x6539;&#x540E;&#x7684;&#x5E7F;&#x64AD;</li>
</ul>
</li>
<li><p>&#x7CFB;&#x7EDF;&#x5E7F;&#x64AD;</p>
<p>Android &#x7CFB;&#x7EDF;&#x4E2D;&#x5185;&#x7F6E;&#x4E86;&#x591A;&#x4E2A;&#x5E7F;&#x64AD;&#xFF0C;&#x5728;&#x7CFB;&#x7EDF;&#x8FDB;&#x884C;&#x67D0;&#x4E9B;&#x4F8B;&#x5982;&#x5F00;&#x673A;&#x3001;&#x62CD;&#x7167;&#x3001;&#x7F51;&#x7EDC;&#x53D8;&#x5316;&#x7B49;&#x64CD;&#x4F5C;&#x65F6;&#x4F1A;&#x53D1;&#x51FA;&#x5BF9;&#x5E94;&#x7684;&#x5E7F;&#x64AD;</p>
</li>
<li><p>&#x5E94;&#x7528;&#x672C;&#x5730;&#x5E7F;&#x64AD;</p>
<p>&#x672C;&#x5730;&#x5E7F;&#x64AD;&#x53EF;&#x4EE5;&#x7406;&#x89E3;&#x4E3A;&#x4E00;&#x4E2A;&#x5C40;&#x90E8;&#x5E7F;&#x64AD;&#xFF0C;&#x5E7F;&#x64AD;&#x7684;&#x53D1;&#x51FA;&#x8005;&#x548C;&#x63A5;&#x6536;&#x8005;&#x90FD;&#x662F;&#x5F53;&#x524D; App&#x3002;</p>
<p>&#x4E3A;&#x4E86;&#x89E3;&#x51B3;&#x5176;&#x4ED6; App &#x4E2D;&#x5B58;&#x5728;&#x4E0E;&#x81EA;&#x5DF1;&#x7684; App &#x4E2D; intentFilter &#x76F8;&#x540C;&#x7684;&#x5E7F;&#x64AD;&#xFF0C;&#x4ECE;&#x800C;&#x5BFC;&#x81F4;&#x5F53;&#x524D; App &#x4E0D;&#x65AD;&#x63A5;&#x6536;&#x5176;&#x4ED6; App &#x53D1;&#x51FA;&#x7684;&#x5E7F;&#x64AD;&#xFF0C;&#x548C;&#x5176;&#x4ED6; App &#x80FD;&#x591F;&#x6536;&#x5230;&#x5F53;&#x524D; App &#x53D1;&#x51FA;&#x7684;&#x5E7F;&#x64AD;&#x7684;&#x95EE;&#x9898;&#x3002;</p>
<p>&#x76F8;&#x6BD4;&#x666E;&#x901A;&#x5E7F;&#x64AD;&#xFF0C;&#x672C;&#x5730;&#x5E7F;&#x64AD;&#x4F18;&#x52BF;&#x5728;&#x4E8E;&#x5B89;&#x5168;&#x6027;&#x548C;&#x6548;&#x7387;&#x9AD8;&#x3002;</p>
<p>&#x4F7F;&#x7528;</p>
<p>&#x5C06;&#x5168;&#x5C40;&#x5E7F;&#x64AD;&#x8BBE;&#x7F6E;&#x4E3A;&#x672C;&#x5730;&#x5E7F;&#x64AD;</p>
<ul>
<li><p>&#x6CE8;&#x518C;&#x65F6;&#x5C06; exported &#x8BBE;&#x7F6E;&#x4E3A;false</p>
</li>
<li><p>&#x5728;&#x53D1;&#x9001;&#x548C;&#x63A5;&#x6536;&#x65F6;&#x6DFB;&#x52A0;&#x6743;&#x9650;&#x8FDB;&#x884C;&#x9A8C;&#x8BC1;</p>
</li>
<li>&#x901A;&#x8FC7; intent.setPackage() &#x6307;&#x5B9A;&#x5305;&#x540D;</li>
</ul>
<p>&#x4F7F;&#x7528; LocalBrodcastManager &#x53D1;&#x9001;&#x5E94;&#x7528;&#x5185;&#x5E7F;&#x64AD;</p>
</li>
</ul>
<pre><code class="lang-java">LocalBroadcastManager localBroadcastManager = LocalBroadcastManager.getInstance(<span class="hljs-keyword">this</span>);
IntentFilter intentFilter = <span class="hljs-keyword">new</span> IntentFilter();
intentFilter.addAction(<span class="hljs-string">&quot;LOCAL_BROADCAST_ACTION&quot;</span>);
<span class="hljs-comment">//register</span>
localBroadcastManager.registerReceiver(broadcastReceiver, intentFilter);
<span class="hljs-comment">//unregister</span>


<span class="hljs-comment">//send</span>
Intent intent = <span class="hljs-keyword">new</span> Intent();
intent.setAction(<span class="hljs-string">&quot;LOCAL_BROADCAST_ACTION&quot;</span>);
LocalBroadcastManager.getInstance(<span class="hljs-keyword">this</span>).sendBroadcast(intent);
</code></pre>
<ul>
<li><p>&#x7C98;&#x6027;&#x5E7F;&#x64AD;</p>
<p>&#x5728; Android 5.0 &amp; API 21 &#x5DF2;&#x5931;&#x6548;</p>
</li>
</ul>
<h3 id="&#x9759;&#x6001;&#x6CE8;&#x518C;&#x4E0E;&#x52A8;&#x6001;&#x6CE8;&#x518C;&#x7684;&#x533A;&#x522B;">&#x9759;&#x6001;&#x6CE8;&#x518C;&#x4E0E;&#x52A8;&#x6001;&#x6CE8;&#x518C;&#x7684;&#x533A;&#x522B;</h3>
<p><img src="pic/BroadcastReceiver&#x4E24;&#x79CD;&#x6CE8;&#x518C;&#x65B9;&#x5F0F;&#x7684;&#x533A;&#x522B;.png" alt=""></p>
<p>&#x52A8;&#x6001;&#x6CE8;&#x518C;</p>
<pre><code class="lang-java"><span class="hljs-meta">@Override</span>
<span class="hljs-function"><span class="hljs-keyword">protected</span> <span class="hljs-keyword">void</span> <span class="hljs-title">onResume</span><span class="hljs-params">()</span> </span>{
    <span class="hljs-keyword">super</span>.onResume();
    Log.e(<span class="hljs-string">&quot;borax MainActivity&quot;</span>, <span class="hljs-string">&quot;onResume()&quot;</span>);

    IntentFilter intentFilter = <span class="hljs-keyword">new</span> IntentFilter();
    intentFilter.addAction(<span class="hljs-string">&quot;MY_BROADCAST_ACTION&quot;</span>);
    registerReceiver(broadcastReceiver, intentFilter);

}

<span class="hljs-meta">@Override</span>
<span class="hljs-function"><span class="hljs-keyword">protected</span> <span class="hljs-keyword">void</span> <span class="hljs-title">onDestroy</span><span class="hljs-params">()</span> </span>{
    <span class="hljs-keyword">super</span>.onDestroy();
    Log.e(<span class="hljs-string">&quot;borax MainActivity&quot;</span>, <span class="hljs-string">&quot;onDestroy&quot;</span>);
    unregisterReceiver(broadcastReceiver);
}
</code></pre>
<p>&#x9759;&#x6001;&#x6CE8;&#x518C;</p>
<pre><code class="lang-java">&lt;receiver android:name=&quot;.activity.MyBroadcastReceiver&quot;&gt;

    &lt;intent-filter&gt;
        &lt;action android:name=&quot;MY_BROADCAST_ACTION&quot;/&gt;
    &lt;/intent-filter&gt;

&lt;/receiver&gt;
</code></pre>
<h3 id="&#x5E7F;&#x64AD;&#x7684;&#x5DE5;&#x4F5C;&#x539F;&#x7406;">&#x5E7F;&#x64AD;&#x7684;&#x5DE5;&#x4F5C;&#x539F;&#x7406;</h3>
<ul>
<li>&#x5E7F;&#x64AD;&#x63A5;&#x6536;&#x8005; &#x901A;&#x8FC7; Binder &#x673A;&#x5236;&#x5728; AMS&#xFF08;Android Manager Service &#x6D88;&#x606F;&#x4E2D;&#x5FC3;&#xFF09;&#x6CE8;&#x518C;</li>
<li>&#x5E7F;&#x64AD;&#x53D1;&#x9001;&#x8005; &#x901A;&#x8FC7; Binder &#x673A;&#x5236;&#x5411; AMS &#x53D1;&#x9001;&#x5E7F;&#x64AD;</li>
<li>AMS &#x6839;&#x636E; &#x5E7F;&#x64AD;&#x53D1;&#x9001;&#x8005; &#x7684;&#x8981;&#x6C42;&#xFF0C;&#x5728;&#x5DF2;&#x6CE8;&#x518C;&#x5217;&#x8868;&#x4E2D;&#x5BFB;&#x627E;&#x5408;&#x9002;&#x7684; &#x5E7F;&#x64AD;&#x63A5;&#x6536;&#x8005;&#x3002;&#x5BFB;&#x627E;&#x4F9D;&#x636E;&#xFF1A;IntentFilter&#x3001;Permission</li>
<li>AMS &#x5C06;&#x5E7F;&#x64AD;&#x53D1;&#x9001;&#x5230;&#x5408;&#x9002;&#x7684;&#x5E7F;&#x64AD;&#x63A5;&#x6536;&#x8005;&#x7684;&#x6D88;&#x606F;&#x5FAA;&#x73AF;&#x961F;&#x5217;&#x4E2D;</li>
<li>&#x5E7F;&#x64AD;&#x63A5;&#x6536;&#x8005; &#x901A;&#x8FC7;&#x6D88;&#x606F;&#x5FAA;&#x73AF;&#x961F;&#x5217;&#x62FF;&#x5230;&#x5E7F;&#x64AD;&#xFF0C;&#x5E76;&#x56DE;&#x8C03; onReceive &#x65B9;&#x6CD5;</li>
</ul>
<h3 id="&#x5982;&#x4F55;&#x901A;&#x8FC7;&#x5E7F;&#x64AD;&#x62E6;&#x622A;&#x4E00;&#x6761;&#x77ED;&#x4FE1;">&#x5982;&#x4F55;&#x901A;&#x8FC7;&#x5E7F;&#x64AD;&#x62E6;&#x622A;&#x4E00;&#x6761;&#x77ED;&#x4FE1;</h3>

                                
                                </section>
                            
    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

                        </div>
                    </div>
                
            </div>

            
                
                <a href="ContentProvider.html" class="navigation navigation-prev " aria-label="Previous page: ContentProvider">
                    <i class="fa fa-angle-left"></i>
                </a>
                
                
                <a href="../Fragment.html" class="navigation navigation-next " aria-label="Next page: Fragment">
                    <i class="fa fa-angle-right"></i>
                </a>
                
            
        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"title":"BroadcastReceiver","level":"1.2.1.4","depth":3,"next":{"title":"Fragment","level":"1.2.2","depth":2,"path":"Android/Fragment.md","ref":"Android/Fragment.md","articles":[]},"previous":{"title":"ContentProvider","level":"1.2.1.3","depth":3,"path":"Android/四大组件/ContentProvider.md","ref":"Android/四大组件/ContentProvider.md","articles":[]},"dir":"ltr"},"config":{"gitbook":"*","theme":"default","variables":{},"plugins":["livereload"],"pluginsConfig":{"livereload":{},"highlight":{},"search":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"fontsettings":{"theme":"white","family":"sans","size":2},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"}},"file":{"path":"Android/四大组件/BroadcastReceiver.md","mtime":"2019-01-22T09:19:30.462Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2019-01-21T14:04:13.553Z"},"basePath":"../..","book":{"language":""}});
        });
    </script>
</div>

        
    <script src="../../gitbook/gitbook.js"></script>
    <script src="../../gitbook/theme.js"></script>
    
        
        <script src="../../gitbook/gitbook-plugin-livereload/plugin.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-search/search-engine.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-search/search.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-lunr/lunr.min.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-lunr/search-lunr.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-sharing/buttons.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
        
    

    </body>
</html>

